"""
fastapi 服务
"""
import uvicorn
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware


def create_app():
    app = FastAPI(title="Eastern Translate API Server", version='1.0')
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
    mount_chat_routes(app)
    return app


def mount_chat_routes(app: FastAPI):

    from services.api import upload_file_api, list_files_api, download_files_api
    from services.api import create_mcp_proxy_api

    app.post(
        path='/upload', summary="用户文件上传"
    )(upload_file_api)

    app.post(
        path='/list', summary="用户文件列表"
    )(list_files_api)

    app.post(
        path='/download', summary="用户文件下载"
    )(download_files_api)

    app.post(
        path='/create_mcp_proxy_api', summary="基于mcp_proxy创建沙箱mcp-sse服务"
    )(create_mcp_proxy_api)


my_app = create_app()
my_app.mount("/files", StaticFiles(directory="files"), name="files")


if __name__ == '__main__':
    uvicorn.run(app=my_app, host="0.0.0.0", port=8921, reload=False)
